home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / ROMBIOS.ASM < prev    next >
Assembly Source File  |  1990-10-22  |  9KB  |  285 lines

  1. ; ROMBIOS.ASM
  2. ;
  3. ; by Ralph Davis
  4. ; modified by Rick Spence
  5. ;
  6. ; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. ;
  8.             PUBLIC ROMBIOS
  9.  
  10.             EXTRN __TR_HTOI:FAR          ; Library C function (hex-to-integer)
  11.             EXTRN __TR_ITOD:FAR          ; Library C function (integer-to-double)
  12.             EXTRN __TR_DTOI:FAR          ; Library C function (double-to-integer)
  13.             EXTRN __TR_HEXASM:FAR        ; Produces hex string
  14.  
  15. PARMS_IN    STRUC
  16.  
  17. BP_OLD      DW      ?
  18. RET_ADDR    DD      ?
  19. INT_NUM     DW      ?
  20. IN_PARM     DD      ?
  21. FLAG_PARM   DD      ?
  22.  
  23. PARMS_IN    ENDS
  24.  
  25. ;****************************************
  26. ROMBIOS_TEXT SEGMENT BYTE PUBLIC 'CODE'
  27.             ASSUME  CS:ROMBIOS_TEXT
  28. ;----------------------------------------
  29. ROMBIOS     PROC    FAR            ; ROM BIOS interface
  30.             JMP     SHORT GO
  31.  
  32. PCOUNT      DW      0              ; Counts parameters passed
  33. SAVE_COUNT  DW      8              ; Saves count
  34. THIS_PARM   DB      4 DUP (?),0    ; Holds current parameter
  35. ABS_DISK    DB      0              ; INT 25H or 26H
  36. PRE_INT_BP  DW      ?              ; INT 25H and 26H destroy BP
  37.  
  38. ; Register values passed
  39. AX_IN       DW      ?
  40. BX_IN       DW      ?   
  41. CX_IN       DW      ?
  42. DX_IN       DW      ?
  43. SI_IN       DW      ?
  44. DI_IN       DW      ?
  45. DS_IN       DW      ?
  46. ES_IN       DW      ?
  47.  
  48. ; Register return values
  49. AX_OUT      DW      ?
  50. BX_OUT      DW      ?
  51. CX_OUT      DW      ?
  52. DX_OUT      DW      ?
  53. SI_OUT      DW      ?
  54. DI_OUT      DW      ?
  55. DS_OUT      DW      ?
  56. ES_OUT      DW      ?
  57.  
  58. ; Parameter pointer table
  59.  
  60. PARM1_PTR   DW      ?
  61.             DW      ?
  62. PARM2_PTR   DW      ?
  63.             DW      ?
  64. PARM3_PTR   DW      ?
  65.             DW      ?
  66. PARM4_PTR   DW      ?
  67.             DW      ?
  68. PARM5_PTR   DW      ?
  69.             DW      ?
  70. PARM6_PTR   DW      ?
  71.             DW      ?
  72. PARM7_PTR   DW      ?
  73.             DW      ?
  74. PARM8_PTR   DW      ?
  75.             DW      ?
  76.  
  77. REG_AX      DW      PARM1          ; Jump table
  78. REG_BX      DW      PARM2
  79. REG_CX      DW      PARM3
  80. REG_DX      DW      PARM4
  81. REG_SI      DW      PARM5
  82. REG_DI      DW      PARM6
  83. REG_DS      DW      PARM7
  84. REG_ES      DW      PARM8
  85.  
  86. GO:         PUSH    BP
  87.             MOV     BP,SP
  88.             PUSH    DS
  89.             PUSH    ES
  90.             PUSH    AX
  91.             PUSH    BX
  92.             PUSH    CX
  93.             PUSH    DX
  94.             PUSH    SI
  95.             PUSH    DI
  96.             CLD
  97.             AND     CS:ABS_DISK,0  ; Clear disk interrupt flag
  98.             XOR     AX,AX
  99.             MOV     CS:PCOUNT,AX   ; Initialize parameter counter to 0
  100.             MOV     CX,16          ; Initialize parameter pointer table
  101.             PUSH    CS             ;    (all zeroes)
  102.             POP     ES
  103.             MOV     DI,OFFSET CS:PARM1_PTR
  104.             REP     STOSW
  105.             MOV     AX,[BP].INT_NUM
  106.             CMP     AL,10H         ; don't allow lower than INT 10H
  107.             JGE     INT_OK     
  108.             JMP     ERROR_EXIT
  109. INT_OK:
  110.             CMP     AL,25H            ; check for absolute disk interrupts
  111.             JNE     IS_IT_26H
  112.             MOV     CS:PRE_INT_BP,BP  ; save BP--INT 25H destroys it
  113.             OR      CS:ABS_DISK,0FFH  ; set flag
  114.             JMP     SHORT SET_INT
  115. IS_IT_26H:
  116.             CMP     AL,26H            ; disk write?
  117.             JNE     SET_INT
  118.             MOV     CS:PRE_INT_BP,BP  ; save BP--INT 26H destroys it
  119.             OR      CS:ABS_DISK,0FFH  ; set flag
  120. SET_INT:
  121.             MOV     CS:CALL_ROM[1],AL
  122.             LDS     SI,[BP].IN_PARM
  123.             MOV     DI,OFFSET CS:THIS_PARM
  124.             CALL    CONV_PARM             ; CONV_PARM adds 4 to SI
  125.             INC     CS:PCOUNT
  126.             CALL    CONV_PARM
  127.             INC     CS:PCOUNT
  128.             CALL    CONV_PARM
  129.             INC     CS:PCOUNT
  130.             CALL    CONV_PARM
  131.             INC     CS:PCOUNT
  132.             CALL    CONV_PARM
  133.             INC     CS:PCOUNT
  134.             CALL    CONV_PARM
  135.             INC     CS:PCOUNT
  136.             CALL    CONV_PARM
  137.             INC     CS:PCOUNT
  138.             CALL    CONV_PARM
  139.             INC     CS:PCOUNT
  140.  
  141. CALL_ROM    DB      0CDH,?
  142.             PUSHF
  143.             CMP     CS:ABS_DISK,0FFH   ; was it a disk interrupt?
  144.             JNE     RET_REGS
  145.             POP     BP                 ; if it was, we have to
  146.                                        ; go get the flags,
  147.                                        ; then push them for later
  148.             ADD     SP,2               ; this discards pre-interrupt flags
  149.             PUSH    BP                 ; this saves interrupt state flags
  150.             MOV     BP,CS:PRE_INT_BP   ; restore pre-int BP
  151. RET_REGS:
  152.             MOV     CS:ES_OUT,ES
  153.             MOV     CS:DS_OUT,DS
  154.             MOV     CS:DI_OUT,DI
  155.             MOV     CS:SI_OUT,SI
  156.             MOV     CS:DX_OUT,DX
  157.             MOV     CS:CX_OUT,CX
  158.             MOV     CS:BX_OUT,BX
  159.             MOV     CS:AX_OUT,AX
  160.             MOV     CX,CS:SAVE_COUNT
  161. RET_PARM:   MOV     SI,CX
  162.             DEC     SI
  163.             SHL     SI,1
  164.             XOR     AX,AX
  165.             PUSH    AX
  166.             PUSH    CS:[AX_OUT][SI]
  167.             CALL    __TR_HEXASM
  168.             ADD     SP,4
  169.             SHL     SI,1
  170.             MOV     ES,CS:[PARM1_PTR][SI+2]     ; Destination string pointer
  171.             MOV     DI,CS:[PARM1_PTR][SI]
  172.             MOV     DS,DX                       ; Source string pointer
  173.             MOV     SI,AX
  174.             PUSH    CX
  175.             MOV     CX,4
  176.             REP     MOVSB
  177.             POP     CX
  178.             LOOP    RET_PARM
  179.             JMP     SHORT EXIT
  180. ERROR_EXIT: 
  181.             STC                  ; DOS uses Carry flag for error signal
  182. EXIT:       LDS     SI,[BP].FLAG_PARM
  183.             POPF
  184.             PUSHF
  185.             POP    AX
  186.             MOV    [SI],AX
  187.             POP     DI
  188.             POP     SI
  189.             POP     DX
  190.             POP     CX
  191.             POP     BX
  192.             POP     AX
  193.             POP     ES
  194.             POP     DS
  195.             POP     BP
  196.             RET
  197. ROMBIOS     ENDP
  198. ;----------------------------------------------------
  199. CONV_PARM   PROC    NEAR
  200.             MOV     BX,CS:PCOUNT
  201.             PUSH    BX
  202.             SHL     BX,1
  203.             SHL     BX,1
  204.             MOV     CS:PARM1_PTR[BX],SI
  205.             MOV     CS:PARM1_PTR[BX+2],DS
  206.             PUSH    CX
  207.             MOV     CX,4
  208.     
  209.             ; DS:SI points to instring--ES:DI points to THIS_PARM
  210.             REP     MOVSB
  211.             SUB     DI,4
  212.             PUSH    DX
  213.             PUSH    SI             ; at this point, SI points to next parm 
  214.             PUSH    ES             ; pass location
  215.             PUSH    DI
  216.             CALL    __TR_HTOI       ; AX now holds integer value
  217.             POP     DI
  218.             POP     ES
  219.             POP     SI
  220.             POP     DX
  221.             POP     CX
  222.             POP     BX             ; Retrieve PCOUNT
  223.             SHL     BX,1           ; PCOUNT becomes offset into 
  224.                                    ; jump table
  225.             CALL    CS:[REG_AX][BX]
  226.             RET
  227. CONV_PARM   ENDP
  228. ;--------------------------------------------
  229. PARM1       PROC    NEAR
  230.             MOV     CS:AX_IN,AX
  231.             RET
  232. PARM1       ENDP
  233. ;----------------------------------------------------
  234. PARM2       PROC    NEAR
  235.             MOV     CS:BX_IN,AX
  236.             RET
  237. PARM2       ENDP
  238. ;----------------------------------------------------
  239. PARM3       PROC    NEAR
  240.             MOV     CS:CX_IN,AX
  241.             RET
  242. PARM3       ENDP
  243. ;----------------------------------------------------
  244. PARM4       PROC    NEAR
  245.             MOV     CS:DX_IN,AX
  246.             RET
  247. PARM4       ENDP
  248. ;----------------------------------------------------
  249. PARM5       PROC    NEAR
  250.             MOV     CS:SI_IN,AX
  251.             RET
  252. PARM5       ENDP
  253. ;----------------------------------------------------
  254. PARM6       PROC    NEAR
  255.             MOV     CS:DI_IN,AX
  256.             RET
  257. PARM6       ENDP
  258. ;----------------------------------------------------
  259. PARM7       PROC    NEAR
  260.             MOV     CS:DS_IN,AX
  261.             RET
  262. PARM7       ENDP
  263. ;----------------------------------------------------
  264. PARM8       PROC    NEAR
  265.             MOV     BX,CS:BX_IN
  266.             MOV     CX,CS:CX_IN
  267.             MOV     DX,CS:DX_IN
  268.             MOV     SI,CS:SI_IN
  269.             MOV     DI,CS:DI_IN
  270.             CMP     CS:DS_IN,0
  271.             JE      PARM8_ES
  272. PARM8_DS:   MOV     DS,CS:DS_IN
  273.  
  274. PARM8_ES:   CMP     AX,0
  275.             JE      PARM8_RET
  276.             MOV     ES,AX
  277. PARM8_RET:  MOV     AX,AX_IN
  278.             RET
  279. PARM8       ENDP
  280. ;----------------------------------------------------
  281. ROMBIOS_TEXT       ENDS
  282. ;****************************************************
  283.             END
  284.  
  285.